<%str_method = @fleet.id.nil? ?  'post' : 'put'%>
<%str_path = @fleet.id.nil? ? fleets_path : fleet_path%>

<%= form_for(@fleet, :url=> str_path, :method=>str_method,:html=>{:id=>"form_fleet"}) do |f| %>
  <% if @fleet.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@fleet.errors.count, "error") %> prohibited this fleet from being saved:</h2>

      <ul>
      <% @fleet.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<%= field_set_tag text="Información de la flota", :class => "MiFieldSet1" do%>
	<div class="field">
    <%= f.label "Fecha de adquisición" %><br />
    <%= f.date_select :fechaAdquisicion %>
  </div>
  <div class="field">
    <%= f.label :marca %><br />
    <%= f.text_field :marca, :class => "MiTextField1" %>
  </div>
  <div class="field">
    <%= f.label :modelo %><br />
    <%= f.text_field :modelo, :class => "MiTextField1" %>
  </div>
  <div class="field">
    <%= f.label "Año de fabricación" %><br />
    <%= f.text_field :anhoFabricacion, :class => "MiTextField1" %>
  </div>
  <div class="field">
    <%= f.label "Nro. de asientos" %><br />
    <%= f.text_field :numAsientos, :class => "MiTextField1" %>
  </div>
  <div class="field">
    <%= f.label "Nro. de ejes" %><br />
    <%= f.text_field :numLlantas, :class => "MiTextField1" %>
  </div>
  <div class="field">
    <%= hidden_field_tag :numBusesDisp, :value=> (@fleet.id.nil? ? 0 : @fleet.numBusesDisp) %>
  </div>
  <div class="field">
    <%= hidden_field_tag :numBusesNoDisp, :value=> (@fleet.id.nil? ? 0 : @fleet.numBusesDisp) %>
  </div>
  <div class="field">
    <%= f.label "Nro. de buses" %><br />
    <%= f.text_field :numBuses, :class => "MiTextField1" %>
  </div>
  <div class="field">
    <%= label_tag "Tipo de servicio" %><br />
		<% if @fleet.id.nil? then %>
		  <%= select_tag 'tipo_servicio', options_from_collection_for_select(@tipservs, :id, :descripcion), :class => "MiComboBox1" %>
		<% else %>
		  <%= select_tag 'tipo_servicio', options_from_collection_for_select(@tipservs, :id, :descripcion, @fleet.service_type_id), :class => "MiComboBox1" %>
			
		<% end %>
  </div>
<% end %>

	<% if !@fleet.id.nil? then %>
		<%= field_set_tag text="Información los buses", :class => "MiFieldSet1" do%>
			<p>Ingrese las placas de cada bus. Una vez ingresadas las placas, no se podrán modificar.</p>
			<table id="MiTabla1" style="margin-top: 10px;">
				<tr>
					<th class="MiHeader1">Últ. Revisión Técnica</th>
					<th class="MiHeader1">Placa</th>
					<th class="MiHeader1">Estado</th>
					<th class="MiHeader1">Ingresar Placa</th>
					<th class="MiHeader1">Acciones</th>
				</tr>
			<% @buses.each do |b| %>
				<tr>
					<td class="MiCelda1"><%= b.ultRevisionTecnica.in_time_zone("Lima").to_date.to_formatted_s(:rfc822) %></td>
					<td class="MiCelda1"><%= b.placa %></td>
					<% if b.estado == 1 then %>
					<td class="MiCelda1">REGISTRADO</td>
					<% elsif b.estado == 0 then %>
					<td class="MiCelda1">INHABILITADO</td>
					<% elsif b.estado == 2 then %>
					<td class="MiCelda1">HABILITADO</td>
					<% else %>
					<td class="MiCelda1">INCONSISTENTE</td>
					<% end %>
					<% if b.placa == "SIN PLACA" then %>
					<td class="MiCelda1"><%= text_field_tag "placas[p#{b.id}]" %></td>
					<% else %>
					<td class="MiCelda1">Placa registrada</td>
					<% end %>
					<td class="MiCelda1"><%= link_to image_tag("tool.ico", :size => "15x15"), registrar_falla_tecnica_fleet_bus_path(b.fleet,b) %></td>
				</tr>
			<% end %>
			</table>
		<% end %>
	<% end %>

  <div class="actions">
		<% if @fleet.id.nil? then %>
			<%= f.submit "Registrar", :class => "MiBoton1", :style => "margin-right: 5px; margin-bottom: 5px; padding-left: 0px; margin-top: 10px;" %>
		<% else %>
			<%= f.submit "Guardar", :class => "MiBoton1", :style => "margin-right: 5px; margin-bottom: 5px; padding-left: 0px; margin-top: 10px;" %>
		<% end %>
  </div>
<% end %>
